package com.abigdreamer.im.server.ui.desktop.internal;

import java.awt.BorderLayout;
import java.awt.event.MouseEvent;
import java.io.File;

import javax.swing.Icon;

import com.abigdreamer.im.server.log.EIMLogger;
import com.abigdreamer.im.server.log.LoggerFileManager;
import com.abigdreamer.im.server.tools.ServerUtils;
import com.abigdreamer.im.server.ui.BaseFrame;
import com.abigdreamer.im.server.ui.resourse.ResourseMannager;


public class LoggerFrame extends DeskTopFrame{

	
	private LoggerWindow loggerWindow;
	

	
	public LoggerFrame(){
		super("日志信息", true);
		initComponents();
		this.setClosable(true);
		this.setBounds(100, 40, 550, 450);
	}
	
	 private void initComponents() {
		    loggerWindow =new LoggerWindow();
		    this.getContentPane().add(loggerWindow,BorderLayout.CENTER);
	    }



	
}

class LoggerWindow extends EIMWindow{

	public LoggerWindow(){
		File[] files=LoggerFileManager.getLoggerFile();
		for(int i=0;i<files.length;i++){
			LoggerWindowItem item=new LoggerWindowItem();
			String loggername=files[i].getName();
			item.setWindow(this);
			String ext=ServerUtils.getFileExtractor(loggername);
			Icon icon=ResourseMannager.getIconByExtractor(ext, true);
			item.setIcon(icon);
			item.setText(loggername);
			item.setToolTipText("查看"+loggername+"日志信息");
			this.add(item, i+1);
		}
		
	}	
}

class LoggerWindowItem extends WindowItem{

	public void mouseClicked(MouseEvent e) {
		super.mouseClicked(e);
		if(e.getClickCount()==2){
			EIMLogger.INFO("打开了"+this.getText()+"文件");
			File file=ServerUtils.getFile(LoggerFileManager.class.getPackage(), this.getText());
			MiniEdit edit = new MiniEdit();
			edit.setTitle(this.getText()+"-"+edit.getTitle());
			edit.openFile(file);
			BaseFrame.centerWindow(edit);
			edit.setVisible(true);
		}
	}
}

